/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lvoddownloader;

import Lvod.Config.ConfigLoader;
import Lvod.DownLoader;
import Lvod.PlayList.HistoryItem;
import Lvod.PlayList.PlayListLoader;
import Lvod.PlayList.VodUrlFilters;
import LvodServer.SingleHTTPServer;
import LvodUpdater.CheckUpdate;
import PlayerComponent.JPlayerReport;
import PlayerShell.JMplayerLoader;
import VLCPlayerComponent.VLCFrame;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author wcss
 */
public class QvodPlayerUI extends VLCFrame implements LDownloadListActionInterface, Runnable, JPlayerReport, PlayListActionInterface {

    private static final long serialVersionUID = 1L;
    public static long runTimes = 0;
    public String defaultSoftName = "LvodPlayer V3.0";
    private boolean paused = false;
    private boolean outputAllowed = false;
    private int currentVolume = 5;
    private boolean isDownloadPage = true;
    private boolean isMenuShowing = false;

    /**
     * Creates new form QvodPlayerUI
     */
    public QvodPlayerUI() {
        initComponents();
        this.jslVolume.setUI(new LVolumeSliderUI(this.jslVolume));
        this.jslMovieProgress.setUI(new LProgressSliderUI(this.jslMovieProgress));
        try {
            SingleHTTPServer.startListen(this.dlList);
            //this.setTitle(this.getTitle() + " 端口：" + SingleHTTPServer.listenPort);
            //ConfigLoader.config.saveConfig(JAppToolKit.JRunHelper.getUserHomeDirPath() + "/lvod.config");
            ConfigLoader.config.loadConfig();
            setDownloadDir();
            PlayListLoader.loadPlayList();
            this.dlList.downloadActionEvent = this;
            this.player.playerEvents = this;
            this.showPlayButton();
            Thread tt = new Thread(this);
            tt.setDaemon(true);
            tt.start();
            this.lblMovieInfo.setText("");
            JMplayerLoader.MPLAYER = "mplayer";
            this.player.initPlayer();
            this.player.showWelcome();
            setPlayHistory();
            this.setAlwaysOnTop(false);
            this.setTitle(this.lblTitle.getText());
            //this.jslVolume.setValue(0);
            this.getContentPane().setLayout(null);
            this.playHistory.playAction = this;
            this.btnSwitchAddMovie.processButtonPressed();
            this.btnSwitchPlaying.processButtonReleased();
            this.playHistory.loadPlayList();
            checkSoftWareUpdate();
        } catch (Exception ex) {
            Logger.getLogger(QvodDownLoad.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void checkSoftWareUpdate() {
        CheckUpdate.startUpdate();
    }

    public void uploadDownLoadLists() {
        for (Object obj : PlayListLoader.playLists) {
            HistoryItem hin = (HistoryItem) obj;
            try {
                LDownLoadItem ldi = this.dlList.addDownloadItem(hin.downloadUrl, hin.localSaveName, hin.localSaveName, "已停止");
                hin.bufferDir = ldi.downloaderObj.qvodWorkDir;
                hin.bufferSaveName = ldi.downloaderObj.getDownLoadMovieStr(hin.downloadUrl);
            } catch (Exception ex) {
                Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        PlayListLoader.savePlayListWithXML();
        this.dlList.uploadDownloadList();
    }

    public void setPlayHistory() {
        this.playHistory.setLocation(0, this.plTabButtons.getHeight());
        this.playHistory.setSize(255, this.plTask.getHeight() - this.plTabButtons.getHeight());
        this.playHistory.setVisible(false);
    }

    public void showDownloadList() {
        this.plListWork.setVisible(true);
        this.dlList.setVisible(true);
        this.playHistory.setVisible(false);
    }

    public void showPlayHistory() {
        this.plListWork.setVisible(false);
        this.dlList.setVisible(false);
        this.playHistory.setVisible(true);
    }

    /**
     * 设置下载目录
     */
    private void setDownloadDir() {
        File dir = new File(ConfigLoader.config.downloadDir);
        if (dir.exists()) {
            //目录存在，不与处理
        } else {
            ConfigLoader.config.downloadDir = JAppToolKit.JRunHelper.getUserHomeDirPath() + "/视频/QvodMovies";
            File dircreate = new File(ConfigLoader.config.downloadDir);
            dircreate.mkdirs();
        }
    }

    public void showPlayButton() {
        this.btnPause.setVisible(false);
        this.btnPlay.setVisible(false);
        this.btnPause.setLocation(200, 5);
        this.btnPlay.setLocation(200, 5);
        this.btnPause.setVisible(false);
        this.btnPlay.setVisible(true);
        this.btnPause.setLocation(200, 5);
        this.btnPlay.setLocation(200, 5);
    }

    public void showPauseButton() {
        this.btnPause.setVisible(false);
        this.btnPlay.setVisible(false);
        this.btnPause.setLocation(200, 5);
        this.btnPlay.setLocation(200, 5);
        this.btnPause.setVisible(true);
        this.btnPlay.setVisible(false);
        this.btnPause.setLocation(200, 5);
        this.btnPlay.setLocation(200, 5);
    }

    public void playMovie(String moviePath) {
        try {
            this.jslVolume.setValue(0);
            currentVolume = 5;
            this.jslVolume.setValue(5);
            this.jslMovieProgress.setToolTipText("0%");

            if (new File(moviePath).exists()) {
                paused = false;
                //this.btnPlay.setVisible(false);
                this.showPauseButton();
                this.lblMovieInfo.setText(new File(moviePath).getName());
                this.lblMovieInfo.setHorizontalAlignment(SwingConstants.RIGHT);
                //this.btnPlay.setVisible(true);
                this.player.playMovie(moviePath.trim());
            } else {
                javax.swing.JOptionPane.showMessageDialog(null, "文件不存在!");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pmFile = new javax.swing.JPopupMenu();
        miAddDir = new javax.swing.JMenuItem();
        miAddFile = new javax.swing.JMenuItem();
        miAddDVD = new javax.swing.JMenuItem();
        miLoadList = new javax.swing.JMenuItem();
        miSaveList = new javax.swing.JMenuItem();
        miClearList = new javax.swing.JMenuItem();
        topBar = new LPlayerUILib.JImagePanel("/UIImages/top/top-bg.png");
        btnMin = new LPlayerUILib.JImageButton("/UIImages/top/Minimi-1.png","/UIImages/top/Minimi-3.png","/UIImages/top/Minimi-2.png","",true,true);
        btnClose = new LPlayerUILib.JImageButton("/UIImages/top/colse-1.png","/UIImages/top/colse-3.png","/UIImages/top/colse-2.png","",true,true);
        lblTitle = new javax.swing.JLabel();
        lblMovieInfo = new javax.swing.JLabel();
        plMenu = new LPlayerUILib.JImagePanel("/UIImages/top/top-left.png");
        btnFile = new javax.swing.JLabel();
        btnConfig = new javax.swing.JLabel();
        btnAbout = new javax.swing.JLabel();
        contentPanels = new LPlayerUILib.JImagePanel();
        plTask = new LPlayerUILib.JImagePanel("/UIImages/playerbgs/downloadlist_bg.JPG");
        plTabButtons = new LPlayerUILib.JImagePanel();
        btnSwitchAddMovie = new LPlayerUILib.JImageButton("/UIImages/video/Title-2-2.png","/UIImages/video/Title-2.png","/UIImages/video/Title-2.png","",false,false);
        btnSwitchPlaying = new LPlayerUILib.JImageButton("/UIImages/video/Title-1-1.png","/UIImages/video/Title-1.png","/UIImages/video/Title-1.png","",false,false);
        plListWork = new LPlayerUILib.JImagePanel("/UIImages/video/bg-1.png");
        txtDownLoadUrl = new javax.swing.JTextField();
        btnAddMovie = new LPlayerUILib.JImageButton("/UIImages/video/Search-1.png","/UIImages/video/Search-2.png","/UIImages/video/Search-3.png","添加",true,true);
        btnDelMovie = new LPlayerUILib.JImageButton("/UIImages/video/Search-1.png","/UIImages/video/Search-2.png","/UIImages/video/Search-3.png","删除",true,true);
        dlList = new lvoddownloader.LDownLoadList();
        playHistory = new lvoddownloader.LCurrentPlayList("/UIImages/video/bg-1.png");
        plPlayerController = new LPlayerUILib.JImagePanel();
        plPlayerToolBar = new LPlayerUILib.JImagePanel("/UIImages/Footer/Footer-bg.png");
        btnPlay = new LPlayerUILib.JImageButton("/UIImages/Footer/Start-1.png","/UIImages/Footer/Start-3.png","/UIImages/Footer/Start-2.png","",true,true);
        btnStopPlay = new LPlayerUILib.JImageButton("/UIImages/Footer/Stop it-1.png","/UIImages/Footer/Stop it-2.png","/UIImages/Footer/Stop it-2.png","",true,true);
        btnLast = new LPlayerUILib.JImageButton("/UIImages/Footer/last-1.png","/UIImages/Footer/last-2.png","/UIImages/Footer/last-2.png","",true,true);
        btnGoNext = new LPlayerUILib.JImageButton("/UIImages/Footer/Next-1.png","/UIImages/Footer/Next-2.png","/UIImages/Footer/Next-2.png","",true,true);
        btnVolumeAdd = new LPlayerUILib.JImageButton("/UIImages/Footer/Volume-1.png","/UIImages/Footer/Volume-2.png","/UIImages/Footer/Volume-2.png","",true,true);
        btnFullScreen = new LPlayerUILib.JImageButton("/UIImages/Footer/Maximum-1.png","/UIImages/Footer/Maximum-2.png","/UIImages/Footer/Maximum-2.png","",true,true);
        jslVolume = new javax.swing.JSlider();
        btnPause = new LPlayerUILib.JImageButton("/UIImages/Footer/Stop-1.png","/UIImages/Footer/Stop-3.png","/UIImages/Footer/Stop-2.png","",true,true);
        playerflag = new LPlayerUILib.JImagePanel("/UIImages/Footer/doc.png");
        plProgressBar = new LPlayerUILib.JImagePanel("/UIImages/Speed/Speed-bg.png");
        jslMovieProgress = new javax.swing.JSlider();
        btnLeftGo = new LPlayerUILib.JImageButton("/UIImages/Speed/left-1.png","/UIImages/Speed/left-2.png","/UIImages/Speed/left-2.png","",true,true);
        btnRightGo = new LPlayerUILib.JImageButton("/UIImages/Speed/right-1.png","/UIImages/Speed/right-2.png","/UIImages/Speed/right-2.png","",true,true);
        player = new VLCPlayerComponent.VLCMediaPlayer();

        pmFile.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
                pmFilePopupMenuCanceled(evt);
            }
        });

        miAddDir.setText("添加文件夹");
        miAddDir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAddDirActionPerformed(evt);
            }
        });
        pmFile.add(miAddDir);

        miAddFile.setText("添加文件");
        miAddFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAddFileActionPerformed(evt);
            }
        });
        pmFile.add(miAddFile);

        miAddDVD.setText("从DVD中添加");
        miAddDVD.setEnabled(false);
        miAddDVD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAddDVDActionPerformed(evt);
            }
        });
        pmFile.add(miAddDVD);

        miLoadList.setText("影片列表导入");
        miLoadList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miLoadListActionPerformed(evt);
            }
        });
        pmFile.add(miLoadList);

        miSaveList.setText("影片列表导出");
        miSaveList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSaveListActionPerformed(evt);
            }
        });
        pmFile.add(miSaveList);

        miClearList.setText("清空影片列表");
        miClearList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miClearListActionPerformed(evt);
            }
        });
        pmFile.add(miClearList);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        topBar.setLayout(null);

        btnMin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnMinMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnMinLayout = new javax.swing.GroupLayout(btnMin);
        btnMin.setLayout(btnMinLayout);
        btnMinLayout.setHorizontalGroup(
            btnMinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 26, Short.MAX_VALUE)
        );
        btnMinLayout.setVerticalGroup(
            btnMinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );

        topBar.add(btnMin);
        btnMin.setBounds(746, 0, 26, 22);

        btnClose.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCloseMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnCloseLayout = new javax.swing.GroupLayout(btnClose);
        btnClose.setLayout(btnCloseLayout);
        btnCloseLayout.setHorizontalGroup(
            btnCloseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 26, Short.MAX_VALUE)
        );
        btnCloseLayout.setVerticalGroup(
            btnCloseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );

        topBar.add(btnClose);
        btnClose.setBounds(774, 0, 26, 22);

        lblTitle.setFont(lblTitle.getFont().deriveFont(lblTitle.getFont().getStyle() | java.awt.Font.BOLD, lblTitle.getFont().getSize()+3));
        lblTitle.setText("LvodPlayer V3.0");
        topBar.add(lblTitle);
        lblTitle.setBounds(220, 0, 210, 18);

        lblMovieInfo.setFont(lblMovieInfo.getFont().deriveFont(lblMovieInfo.getFont().getSize()+3f));
        lblMovieInfo.setText("无");
        topBar.add(lblMovieInfo);
        lblMovieInfo.setBounds(440, 0, 300, 22);

        plMenu.setBackground(new java.awt.Color(84, 65, 45));
        plMenu.setLayout(null);

        btnFile.setFont(btnFile.getFont().deriveFont(btnFile.getFont().getStyle() | java.awt.Font.BOLD));
        btnFile.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        btnFile.setText("文件");
        btnFile.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btnFileMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                btnFileMouseReleased(evt);
            }
        });
        plMenu.add(btnFile);
        btnFile.setBounds(0, 0, 51, 22);

        btnConfig.setFont(btnConfig.getFont().deriveFont(btnConfig.getFont().getStyle() | java.awt.Font.BOLD));
        btnConfig.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        btnConfig.setText("配置");
        btnConfig.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btnConfigMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                btnConfigMouseReleased(evt);
            }
        });
        plMenu.add(btnConfig);
        btnConfig.setBounds(50, 0, 51, 22);

        btnAbout.setFont(btnAbout.getFont().deriveFont(btnAbout.getFont().getStyle() | java.awt.Font.BOLD));
        btnAbout.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        btnAbout.setText("关于");
        btnAbout.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btnAboutMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                btnAboutMouseReleased(evt);
            }
        });
        plMenu.add(btnAbout);
        btnAbout.setBounds(100, 0, 51, 22);

        topBar.add(plMenu);
        plMenu.setBounds(0, 0, 153, 22);

        getContentPane().add(topBar, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 800, 22));

        contentPanels.setBackground(java.awt.Color.black);
        contentPanels.setLayout(null);

        plTask.setBackground(new java.awt.Color(185, 106, 26));
        plTask.setLayout(null);

        plTabButtons.setBackground(java.awt.Color.black);
        plTabButtons.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnSwitchAddMovie.setBackground(java.awt.Color.black);
        btnSwitchAddMovie.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnSwitchAddMovieMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnSwitchAddMovieLayout = new javax.swing.GroupLayout(btnSwitchAddMovie);
        btnSwitchAddMovie.setLayout(btnSwitchAddMovieLayout);
        btnSwitchAddMovieLayout.setHorizontalGroup(
            btnSwitchAddMovieLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 127, Short.MAX_VALUE)
        );
        btnSwitchAddMovieLayout.setVerticalGroup(
            btnSwitchAddMovieLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 23, Short.MAX_VALUE)
        );

        plTabButtons.add(btnSwitchAddMovie, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        btnSwitchPlaying.setBackground(java.awt.Color.black);
        btnSwitchPlaying.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnSwitchPlayingMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnSwitchPlayingLayout = new javax.swing.GroupLayout(btnSwitchPlaying);
        btnSwitchPlaying.setLayout(btnSwitchPlayingLayout);
        btnSwitchPlayingLayout.setHorizontalGroup(
            btnSwitchPlayingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 127, Short.MAX_VALUE)
        );
        btnSwitchPlayingLayout.setVerticalGroup(
            btnSwitchPlayingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 23, Short.MAX_VALUE)
        );

        plTabButtons.add(btnSwitchPlaying, new org.netbeans.lib.awtextra.AbsoluteConstraints(128, 0, -1, -1));

        plTask.add(plTabButtons);
        plTabButtons.setBounds(0, 0, 255, 23);

        plListWork.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        txtDownLoadUrl.setText("qvod://");
        plListWork.add(txtDownLoadUrl, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 2, 140, -1));

        btnAddMovie.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnAddMovieMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnAddMovieLayout = new javax.swing.GroupLayout(btnAddMovie);
        btnAddMovie.setLayout(btnAddMovieLayout);
        btnAddMovieLayout.setHorizontalGroup(
            btnAddMovieLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 42, Short.MAX_VALUE)
        );
        btnAddMovieLayout.setVerticalGroup(
            btnAddMovieLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 21, Short.MAX_VALUE)
        );

        plListWork.add(btnAddMovie, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 5, 42, 21));

        btnDelMovie.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnDelMovieMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnDelMovieLayout = new javax.swing.GroupLayout(btnDelMovie);
        btnDelMovie.setLayout(btnDelMovieLayout);
        btnDelMovieLayout.setHorizontalGroup(
            btnDelMovieLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 42, Short.MAX_VALUE)
        );
        btnDelMovieLayout.setVerticalGroup(
            btnDelMovieLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 21, Short.MAX_VALUE)
        );

        plListWork.add(btnDelMovie, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 5, 42, 21));

        plTask.add(plListWork);
        plListWork.setBounds(0, 23, 255, 26);
        plTask.add(dlList);
        dlList.setBounds(0, 55, 255, 436);
        plTask.add(playHistory);
        playHistory.setBounds(0, 23, 0, 466);

        contentPanels.add(plTask);
        plTask.setBounds(545, 2, 255, 491);

        plPlayerController.setBackground(new java.awt.Color(171, 146, 120));
        plPlayerController.setLayout(null);

        plPlayerToolBar.setBackground(new java.awt.Color(109, 124, 136));
        plPlayerToolBar.setLayout(null);

        btnPlay.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnPlayMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnPlayLayout = new javax.swing.GroupLayout(btnPlay);
        btnPlay.setLayout(btnPlayLayout);
        btnPlayLayout.setHorizontalGroup(
            btnPlayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 71, Short.MAX_VALUE)
        );
        btnPlayLayout.setVerticalGroup(
            btnPlayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 30, Short.MAX_VALUE)
        );

        plPlayerToolBar.add(btnPlay);
        btnPlay.setBounds(200, 5, 71, 30);

        btnStopPlay.setBackground(new java.awt.Color(182, 187, 191));
        btnStopPlay.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnStopPlayMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnStopPlayLayout = new javax.swing.GroupLayout(btnStopPlay);
        btnStopPlay.setLayout(btnStopPlayLayout);
        btnStopPlayLayout.setHorizontalGroup(
            btnStopPlayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 26, Short.MAX_VALUE)
        );
        btnStopPlayLayout.setVerticalGroup(
            btnStopPlayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );

        plPlayerToolBar.add(btnStopPlay);
        btnStopPlay.setBounds(90, 8, 26, 22);

        btnLast.setBackground(new java.awt.Color(182, 187, 191));
        btnLast.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnLastMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnLastLayout = new javax.swing.GroupLayout(btnLast);
        btnLast.setLayout(btnLastLayout);
        btnLastLayout.setHorizontalGroup(
            btnLastLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 26, Short.MAX_VALUE)
        );
        btnLastLayout.setVerticalGroup(
            btnLastLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );

        plPlayerToolBar.add(btnLast);
        btnLast.setBounds(150, 8, 26, 22);

        btnGoNext.setBackground(new java.awt.Color(182, 187, 191));
        btnGoNext.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnGoNextMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnGoNextLayout = new javax.swing.GroupLayout(btnGoNext);
        btnGoNext.setLayout(btnGoNextLayout);
        btnGoNextLayout.setHorizontalGroup(
            btnGoNextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 26, Short.MAX_VALUE)
        );
        btnGoNextLayout.setVerticalGroup(
            btnGoNextLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );

        plPlayerToolBar.add(btnGoNext);
        btnGoNext.setBounds(300, 8, 26, 22);

        btnVolumeAdd.setBackground(new java.awt.Color(182, 187, 191));
        btnVolumeAdd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnVolumeAddMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnVolumeAddLayout = new javax.swing.GroupLayout(btnVolumeAdd);
        btnVolumeAdd.setLayout(btnVolumeAddLayout);
        btnVolumeAddLayout.setHorizontalGroup(
            btnVolumeAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 26, Short.MAX_VALUE)
        );
        btnVolumeAddLayout.setVerticalGroup(
            btnVolumeAddLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );

        plPlayerToolBar.add(btnVolumeAdd);
        btnVolumeAdd.setBounds(390, 8, 26, 22);

        btnFullScreen.setBackground(new java.awt.Color(182, 187, 191));
        btnFullScreen.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnFullScreenMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnFullScreenLayout = new javax.swing.GroupLayout(btnFullScreen);
        btnFullScreen.setLayout(btnFullScreenLayout);
        btnFullScreenLayout.setHorizontalGroup(
            btnFullScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 26, Short.MAX_VALUE)
        );
        btnFullScreenLayout.setVerticalGroup(
            btnFullScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 22, Short.MAX_VALUE)
        );

        plPlayerToolBar.add(btnFullScreen);
        btnFullScreen.setBounds(540, 8, 26, 22);

        jslVolume.setMaximum(10);
        jslVolume.setPaintTrack(false);
        jslVolume.setValue(0);
        jslVolume.setDoubleBuffered(true);
        jslVolume.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jslVolumeMouseReleased(evt);
            }
        });
        plPlayerToolBar.add(jslVolume);
        jslVolume.setBounds(420, 19, 80, 17);

        btnPause.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnPauseMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnPauseLayout = new javax.swing.GroupLayout(btnPause);
        btnPause.setLayout(btnPauseLayout);
        btnPauseLayout.setHorizontalGroup(
            btnPauseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 71, Short.MAX_VALUE)
        );
        btnPauseLayout.setVerticalGroup(
            btnPauseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 30, Short.MAX_VALUE)
        );

        plPlayerToolBar.add(btnPause);
        btnPause.setBounds(640, 5, 71, 30);

        playerflag.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                playerflagMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                playerflagMouseReleased(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                playerflagMouseExited(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                playerflagMouseEntered(evt);
            }
        });
        playerflag.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                playerflagMouseDragged(evt);
            }
        });
        playerflag.setLayout(null);
        plPlayerToolBar.add(playerflag);
        playerflag.setBounds(784, 19, 16, 16);

        plPlayerController.add(plPlayerToolBar);
        plPlayerToolBar.setBounds(0, 0, 800, 35);

        contentPanels.add(plPlayerController);
        plPlayerController.setBounds(0, 493, 800, 35);

        plProgressBar.setBackground(new java.awt.Color(46, 37, 28));
        plProgressBar.setToolTipText("");
        plProgressBar.setLayout(null);

        jslMovieProgress.setPaintTrack(false);
        jslMovieProgress.setValue(0);
        jslMovieProgress.setDoubleBuffered(true);
        jslMovieProgress.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jslMovieProgressMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jslMovieProgressMouseReleased(evt);
            }
        });
        plProgressBar.add(jslMovieProgress);
        jslMovieProgress.setBounds(45, 7, 450, 16);

        btnLeftGo.setBackground(new java.awt.Color(51, 51, 51));
        btnLeftGo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnLeftGoMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnLeftGoLayout = new javax.swing.GroupLayout(btnLeftGo);
        btnLeftGo.setLayout(btnLeftGoLayout);
        btnLeftGoLayout.setHorizontalGroup(
            btnLeftGoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 27, Short.MAX_VALUE)
        );
        btnLeftGoLayout.setVerticalGroup(
            btnLeftGoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        plProgressBar.add(btnLeftGo);
        btnLeftGo.setBounds(15, 5, 27, 20);

        btnRightGo.setBackground(new java.awt.Color(51, 51, 51));
        btnRightGo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnRightGoMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout btnRightGoLayout = new javax.swing.GroupLayout(btnRightGo);
        btnRightGo.setLayout(btnRightGoLayout);
        btnRightGoLayout.setHorizontalGroup(
            btnRightGoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 27, Short.MAX_VALUE)
        );
        btnRightGoLayout.setVerticalGroup(
            btnRightGoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        plProgressBar.add(btnRightGo);
        btnRightGo.setBounds(500, 5, 27, 20);

        contentPanels.add(plProgressBar);
        plProgressBar.setBounds(0, 463, 545, 30);
        contentPanels.add(player);
        player.setBounds(0, 0, 540, 455);

        getContentPane().add(contentPanels, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 21, 800, 528));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
//        this.btnSwitchAddMovie.processButtonPressed();
//        this.btnSwitchPlaying.processButtonReleased();
    }//GEN-LAST:event_formWindowActivated

    private void btnCloseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCloseMouseClicked
        // TODO add your handling code here:
        this.dlList.stopAllDownload();
        System.exit(0);
    }//GEN-LAST:event_btnCloseMouseClicked

    private void btnMinMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnMinMouseClicked
        // TODO add your handling code here:
        this.setExtendedState(JFrame.ICONIFIED);
    }//GEN-LAST:event_btnMinMouseClicked

    private void btnSwitchAddMovieMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSwitchAddMovieMouseClicked
        // TODO add your handling code here:
        isDownloadPage = true;
        this.btnSwitchAddMovie.processButtonPressed();
        try {
            Thread.sleep(50);
        } catch (InterruptedException ex) {
            Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.btnSwitchPlaying.processButtonReleased();
        this.showDownloadList();
        //this.invalidate();
    }//GEN-LAST:event_btnSwitchAddMovieMouseClicked

    private void btnSwitchPlayingMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSwitchPlayingMouseClicked
        // TODO add your handling code here:
        isDownloadPage = false;
        this.btnSwitchAddMovie.processButtonReleased();
        try {
            Thread.sleep(50);
        } catch (InterruptedException ex) {
            Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.btnSwitchPlaying.processButtonPressed();
        this.showPlayHistory();
        //this.invalidate();
    }//GEN-LAST:event_btnSwitchPlayingMouseClicked

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        uploadDownLoadLists();
    }//GEN-LAST:event_formWindowOpened

    private void btnAddMovieMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAddMovieMouseClicked
        // TODO add your handling code here:
        if (this.txtDownLoadUrl.getText().isEmpty()) {
            javax.swing.JOptionPane.showMessageDialog(null, "请输入下载地址！");
        } else {
            try {
                String movieName = VodUrlFilters.decodeMovieName(VodUrlFilters.getMovieStr(this.txtDownLoadUrl.getText()));
                LDownLoadItem ldi = dlList.addDownloadItem(this.txtDownLoadUrl.getText(), movieName, movieName, "已停止");
                PlayListLoader.addHistory(this.txtDownLoadUrl.getText(), ldi.downloaderObj.qvodWorkDir, ldi.downloaderObj.getDownLoadMovieStr(this.txtDownLoadUrl.getText()), movieName);
                PlayListLoader.savePlayListWithXML();
                dlList.uploadDownloadList();
            } catch (Exception ex) {
                Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                javax.swing.JOptionPane.showMessageDialog(null, "地址错误！");
            }
        }
    }//GEN-LAST:event_btnAddMovieMouseClicked

    private void btnDelMovieMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnDelMovieMouseClicked
        // TODO add your handling code here:
        if (this.dlList.selectedDownLoadItem != null) {
            int result = javax.swing.JOptionPane.showConfirmDialog(null, "真的要删除吗？", "提示", javax.swing.JOptionPane.YES_NO_OPTION);
            if (result == 0) {
                DownLoader dl = this.dlList.selectedDownLoadItem.downloaderObj;
                if (dl != null) {
                    if (dl.isRunning()) {
                        try {
                            dl.stop();
                        } catch (Exception ex) {
                            Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
                this.dlList.removeDownloadItem(this.dlList.selectedDownLoadItem.downloadUrl);
                PlayListLoader.playLists.remove(PlayListLoader.findHistory(this.dlList.selectedDownLoadItem.downloadUrl));
                try {
                    PlayListLoader.savePlayListWithXML();
                } catch (Exception ex) {
                    Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                }

                File ff = new File(ConfigLoader.config.downloadDir + "/" + dlList.selectedDownLoadItem.movieShowName);
                if (ff.exists()) {
                    int resa = javax.swing.JOptionPane.showConfirmDialog(null, "检测到下载目录中有影片文件，是否删除？", "提示", javax.swing.JOptionPane.YES_NO_OPTION);
                    if (resa == 0) {
                        try {
                            JAppToolKit.JRunHelper.runSysCmd("rm -rf " + dl.qvodWorkDir);
                        } catch (Exception ex) {
                            Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        try {
                            JAppToolKit.JRunHelper.runSysCmd("rm -rf " + ff.getAbsolutePath());
                        } catch (Exception ex) {
                            Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                } else {
                    try {
                        JAppToolKit.JRunHelper.runSysCmd("rm -rf " + dl.qvodWorkDir);
                    } catch (Exception ex) {
                        Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }

                this.dlList.uploadDownloadList();
            }
        }
    }//GEN-LAST:event_btnDelMovieMouseClicked

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        this.dlList.stopAllDownload();
    }//GEN-LAST:event_formWindowClosing

    private void btnPlayMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnPlayMouseClicked
        // TODO add your handling code here:
        if (dlList.currentPlay != null || playHistory.currentPlayItem != null) {
            paused = !paused;
            this.player.pausePlay();
        } else {
            if (isDownloadPage) {
                dlList.currentPlay = this.dlList.selectedDownLoadItem;
                try {
                    if ((int) ((dlList.currentPlay.downloaderObj.getCurrentLength() / dlList.currentPlay.downloaderObj.movieFileLength) * 100) >= 98) {
                        this.dlList.selectedDownLoadItem.setPlayButton(false);
                        this.dlList.selectedDownLoadItem.setPauseButton(true);
                        this.playMovie(dlList.currentPlay.downloaderObj.qvodWorkDir + "/" + dlList.currentPlay.downloaderObj.getMovieFileName());
                    } else {
                        String destfile = ConfigLoader.config.downloadDir + "/" + dlList.currentPlay.movieShowName;
                        if (new File(destfile).exists()) {
                            this.dlList.selectedDownLoadItem.setPlayButton(false);
                            this.dlList.selectedDownLoadItem.setPauseButton(true);
                            this.playMovie(destfile);
                        } else {
                            dlList.currentPlay = null;
                        }
                    }
                } catch (Exception ex) {
                    Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
                playHistory.currentPlayItem = playHistory.selectedItem;
                this.playMovie(playHistory.currentPlayItem.moviePath);
            }
        }
        this.showPauseButton();
    }//GEN-LAST:event_btnPlayMouseClicked

    private void btnLastMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnLastMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_btnLastMouseClicked

    private void btnGoNextMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnGoNextMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_btnGoNextMouseClicked

    private void btnVolumeAddMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnVolumeAddMouseClicked
        // TODO add your handling code here:
        this.player.moveVolumeToUp();
        currentVolume += 1;
        this.jslVolume.setValue(currentVolume);
    }//GEN-LAST:event_btnVolumeAddMouseClicked

    private void btnFullScreenMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnFullScreenMouseClicked
        // TODO add your handling code here:        
        this.player.fullScreenPlay();
        btnStopPlayMouseClicked(null);
    }//GEN-LAST:event_btnFullScreenMouseClicked

    private void btnLeftGoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnLeftGoMouseClicked
        // TODO add your handling code here:
        if (this.jslMovieProgress.getValue() >= 10) {
            this.jslMovieProgress.setValue(this.jslMovieProgress.getValue() - 2);
            this.player.seekPlay(this.jslMovieProgress.getValue());
        }
    }//GEN-LAST:event_btnLeftGoMouseClicked

    private void btnRightGoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnRightGoMouseClicked
        // TODO add your handling code here:
        if (this.jslMovieProgress.getValue() < 100) {
            this.jslMovieProgress.setValue(this.jslMovieProgress.getValue() + 2);
            if (this.jslMovieProgress.getValue() >= 100) {
                btnStopPlayMouseClicked(null);
            } else {
                this.player.seekPlay(this.jslMovieProgress.getValue());
            }
        }
    }//GEN-LAST:event_btnRightGoMouseClicked

    private void jslMovieProgressMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jslMovieProgressMouseReleased
        // TODO add your handling code here:
        this.player.seekPlay(this.jslMovieProgress.getValue());
        this.player.pausePlay();
    }//GEN-LAST:event_jslMovieProgressMouseReleased

    private void jslVolumeMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jslVolumeMouseReleased
        // TODO add your handling code here:
        int change = 0;
        if (this.jslVolume.getValue() > currentVolume) {
            change = this.jslVolume.getValue() - currentVolume;
            this.player.jumpVolumeToUp(change);
        } else {
            change = currentVolume - this.jslVolume.getValue();
            this.player.jumpVolumeToDown(change);
        }
        currentVolume = this.jslVolume.getValue();
    }//GEN-LAST:event_jslVolumeMouseReleased

    private void btnPauseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnPauseMouseClicked
        // TODO add your handling code here:
        paused = !paused;
        this.player.pausePlay();
        this.showPlayButton();
    }//GEN-LAST:event_btnPauseMouseClicked

    private void btnStopPlayMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnStopPlayMouseClicked
        // TODO add your handling code here:
        this.player.stopPlay();
        this.jslMovieProgress.setValue(0);
        this.currentVolume = 5;
        this.jslVolume.setValue(this.currentVolume);
        this.showPlayButton();
        this.lblMovieInfo.setText("");
        if (dlList.currentPlay != null) {
            dlList.currentPlay.setPlayButton(true);
            dlList.currentPlay.setPauseButton(false);
        }
        dlList.currentPlay = null;
        dlList.lastPlayItem = null;
        playHistory.currentPlayItem = null;
    }//GEN-LAST:event_btnStopPlayMouseClicked
    private Point oldPoint = null;
    private Point currentPoint = null;

    private void playerflagMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playerflagMousePressed
        // TODO add your handling code here:
        oldPoint = evt.getLocationOnScreen();
    }//GEN-LAST:event_playerflagMousePressed

    private void playerflagMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playerflagMouseDragged
        // TODO add your handling code here:
        if (oldPoint != null) {
            currentPoint = evt.getLocationOnScreen();
            if (currentPoint != null) {
                int nowWidth = 0;
                int nowHeight = 0;
                if (currentPoint.getX() > oldPoint.getX()) {
                    nowWidth = this.getWidth() + ((int) currentPoint.getX() - (int) oldPoint.getX());
                } else {
                    nowWidth = this.getWidth() - ((int) oldPoint.getX() - (int) currentPoint.getX());
                }

                if (currentPoint.getY() > oldPoint.getY()) {
                    nowHeight = this.getHeight() + ((int) currentPoint.getY() - (int) oldPoint.getY());
                } else {
                    nowHeight = this.getHeight() - ((int) oldPoint.getY() - (int) currentPoint.getY());
                }
                oldPoint = evt.getLocationOnScreen();
                this.setSize(nowWidth, nowHeight);
                this.setPreferredSize(new Dimension(nowWidth, nowHeight));
                //System.out.println("width:" + this.getContentPane().getWidth());
                if (this.player.currentPlayers != null) {
                    this.player.showPlayer();
                } else {
                    this.player.showWelcome();
                }
                //checkCompoients();
            }
        }

    }//GEN-LAST:event_playerflagMouseDragged

    private void playerflagMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playerflagMouseReleased
        // TODO add your handling code here:
        oldPoint = null;
    }//GEN-LAST:event_playerflagMouseReleased

    private void checkCompoients() {
        //计算框架的大小及坐标
        //this.setVisible(false);
        this.topBar.setSize(this.getWidth(), this.topBar.getHeight());
        this.contentPanels.setSize(this.getWidth(), this.getHeight() - this.topBar.getHeight());
        this.topBar.setLocation(0, 0);
        this.contentPanels.setLocation(0, this.topBar.getHeight());
        //this.topBar.validate();
        //this.contentPanels.validate();

        //计算标题栏内的组件的大小及坐标
        this.plMenu.setLocation(0, 0);
        this.btnClose.setLocation(this.topBar.getWidth() - this.btnClose.getWidth(), 0);
        this.btnMin.setLocation(this.topBar.getWidth() - (this.btnMin.getWidth() * 2), 0);
        this.lblTitle.setLocation(this.plMenu.getWidth() + 5, 0);
        this.lblMovieInfo.setLocation((this.lblTitle.getWidth() + this.plMenu.getWidth() + 5), 0);
        this.lblMovieInfo.setSize(this.topBar.getWidth() - ((this.btnMin.getWidth() * 2) + (this.lblTitle.getWidth() + this.plMenu.getWidth() + 5)), this.lblMovieInfo.getHeight());
        //this.btnClose.validate();
        //this.btnMin.validate();
        //this.lblTitle.validate();
        //this.lblMovieInfo.validate();

        //计算内容面板中组件的大小及坐标
        this.plTask.setLocation(this.contentPanels.getWidth() - this.plTask.getWidth(), 2);
        this.plTask.setSize(this.plTask.getWidth(), this.contentPanels.getHeight() - 37);
        this.player.setLocation(0, 0);
        this.player.setSize(this.contentPanels.getWidth() - this.plTask.getWidth(), this.contentPanels.getHeight() - 65);
        //this.plTask.validate();
        //this.player.validate();

        //计算任务列表中组件的位置
        this.dlList.setSize(this.plTask.getWidth(), this.plTask.getHeight() - 55);
        this.playHistory.setSize(this.plTask.getWidth(), this.plTask.getHeight() - 23);
        //this.dlList.validate();
        //this.playHistory.validate();

        //计算播放控制条的大小和位置
        this.plProgressBar.setLocation(0, this.player.getHeight());
        this.plProgressBar.setSize(this.contentPanels.getWidth() - this.plTask.getWidth(), this.plProgressBar.getHeight());
        this.plPlayerController.setLocation(0, this.plProgressBar.getY() + this.plProgressBar.getHeight());
        this.plPlayerController.setSize(this.contentPanels.getWidth(), this.plPlayerController.getHeight());
        this.plPlayerToolBar.setLocation(0, 0);
        this.plPlayerToolBar.setSize(this.contentPanels.getWidth(), this.plPlayerToolBar.getHeight());
        //this.plProgressBar.validate();
        //this.plPlayerController.validate();
        //this.plPlayerToolBar.validate();

        //计算播放控制条中按钮的大小和位置
        this.playerflag.setLocation(this.plPlayerToolBar.getWidth() - this.playerflag.getWidth(), this.plPlayerToolBar.getHeight() - this.playerflag.getHeight());
        this.jslMovieProgress.setLocation(20 + this.btnLeftGo.getWidth(), (this.plProgressBar.getHeight() - this.jslMovieProgress.getHeight()) / 2);
        this.jslMovieProgress.setSize(this.plProgressBar.getWidth() - (40 + this.btnLeftGo.getWidth() * 2), this.jslMovieProgress.getHeight());
        this.btnLeftGo.setLocation(10, (this.plProgressBar.getHeight() - this.btnLeftGo.getHeight()) / 2);
        this.btnRightGo.setLocation(this.plProgressBar.getWidth() - (10 + this.btnRightGo.getWidth()), (this.plProgressBar.getHeight() - this.btnRightGo.getHeight()) / 2);
        this.repaint();
    }

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        // TODO add your handling code here:
        checkCompoients();
    }//GEN-LAST:event_formComponentResized

    private void playerflagMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playerflagMouseEntered
        // TODO add your handling code here:
        playerflag.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
    }//GEN-LAST:event_playerflagMouseEntered

    private void playerflagMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playerflagMouseExited
        // TODO add your handling code here:
        playerflag.setCursor(Cursor.getDefaultCursor());
    }//GEN-LAST:event_playerflagMouseExited

    private void btnFileMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnFileMousePressed
        // TODO add your handling code here:
        this.btnFile.setForeground(Color.blue);
        if (isMenuShowing) {
            isMenuShowing = false;
        } else {
            isMenuShowing = true;
            this.pmFile.show(btnFile, 0, 22);
        }
    }//GEN-LAST:event_btnFileMousePressed

    private void btnFileMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnFileMouseReleased
        // TODO add your handling code here:
        this.btnFile.setForeground(Color.black);
    }//GEN-LAST:event_btnFileMouseReleased

    private void btnConfigMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnConfigMousePressed
        // TODO add your handling code here:
        this.btnConfig.setForeground(Color.blue);
        ConfigEditor qpc = new ConfigEditor();
        qpc.setLocationRelativeTo(null);
        qpc.setVisible(true);
    }//GEN-LAST:event_btnConfigMousePressed

    private void btnConfigMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnConfigMouseReleased
        // TODO add your handling code here:
        this.btnConfig.setForeground(Color.black);
    }//GEN-LAST:event_btnConfigMouseReleased

    private void btnAboutMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAboutMousePressed
        // TODO add your handling code here:
        this.btnAbout.setForeground(Color.blue);
        QvodPlayerAbout qpc = new QvodPlayerAbout();
        qpc.setLocationRelativeTo(null);
        qpc.setVisible(true);
    }//GEN-LAST:event_btnAboutMousePressed

    private void btnAboutMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAboutMouseReleased
        // TODO add your handling code here:
        this.btnAbout.setForeground(Color.black);
    }//GEN-LAST:event_btnAboutMouseReleased

    private void miAddDVDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAddDVDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_miAddDVDActionPerformed

    private void miAddDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAddDirActionPerformed
        // TODO add your handling code here:
        isMenuShowing = false;
        javax.swing.JFileChooser jfc = new javax.swing.JFileChooser(".");
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int intRetVal = jfc.showOpenDialog(this);
        if (intRetVal == JFileChooser.APPROVE_OPTION) {
            this.playHistory.addMovieFromDirectory(jfc.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_miAddDirActionPerformed

    private void miAddFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAddFileActionPerformed
        // TODO add your handling code here:
        isMenuShowing = false;
        javax.swing.JFileChooser jfc = new javax.swing.JFileChooser(".");
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int intRetVal = jfc.showOpenDialog(this);
        if (intRetVal == JFileChooser.APPROVE_OPTION) {
            this.playHistory.addMovie(jfc.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_miAddFileActionPerformed

    private void jslMovieProgressMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jslMovieProgressMousePressed
        // TODO add your handling code here:
        this.player.pausePlay();
    }//GEN-LAST:event_jslMovieProgressMousePressed

    private void pmFilePopupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_pmFilePopupMenuCanceled
        // TODO add your handling code here:
        isMenuShowing = false;
    }//GEN-LAST:event_pmFilePopupMenuCanceled

    private void addQvodMovieItem(String qvodurlss) {
        try {
            String movieName = VodUrlFilters.decodeMovieName(VodUrlFilters.getMovieStr(qvodurlss));
            LDownLoadItem ldi = dlList.addDownloadItem(qvodurlss, movieName, movieName, "已停止");
            PlayListLoader.addHistory(qvodurlss, ldi.downloaderObj.qvodWorkDir, ldi.downloaderObj.getDownLoadMovieStr(qvodurlss), movieName);
            PlayListLoader.savePlayListWithXML();
            dlList.uploadDownloadList();
        } catch (Exception ex) {
            Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
            //javax.swing.JOptionPane.showMessageDialog(null, "地址错误！");
        }

    }

    private void miLoadListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLoadListActionPerformed
        // TODO add your handling code here:
        isMenuShowing = false;
        javax.swing.JFileChooser jfc = new javax.swing.JFileChooser(".");
        jfc.setDialogTitle("请选择Qvod地址列表文件！");
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int intRetVal = jfc.showOpenDialog(this);
        if (intRetVal == JFileChooser.APPROVE_OPTION) {
            try {
                String[] steams = JAppToolKit.JDataHelper.readAllLines(jfc.getSelectedFile().getAbsolutePath());
                for (String s : steams) {
                    addQvodMovieItem(s);
                }
            } catch (Exception ex) {
                Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_miLoadListActionPerformed

    private void miSaveListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSaveListActionPerformed
        // TODO add your handling code here:
        isMenuShowing = false;
        javax.swing.JFileChooser jfc = new javax.swing.JFileChooser(".");
        jfc.setDialogTitle("请选择Qvod地址列表文件！");
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int intRetVal = jfc.showSaveDialog(this);
        if (intRetVal == JFileChooser.APPROVE_OPTION) {
            ArrayList alQvodList = new ArrayList();

            Set set = this.dlList.downloadItemMap.keySet();
            Iterator its = set.iterator();
            while (its.hasNext()) {
                String s = (String) its.next();
                alQvodList.add(this.dlList.downloadItemMap.get(s).downloaderObj.qvodUrl);
            }
            try {
                JAppToolKit.JDataHelper.writeAllLines(jfc.getSelectedFile().getAbsolutePath() + ".lql", alQvodList);
            } catch (Exception ex) {
                Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
            }

            javax.swing.JOptionPane.showMessageDialog(null, "导出完成！");
        }
    }//GEN-LAST:event_miSaveListActionPerformed

    public void delQvodMovieItem(LDownLoadItem ldiCur) {
        if (ldiCur != null) {
            int result = 0;
            if (result == 0) {
                DownLoader dl = ldiCur.downloaderObj;
                if (dl != null) {
                    if (dl.isRunning()) {
                        try {
                            dl.stop();
                        } catch (Exception ex) {
                            Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
                this.dlList.removeDownloadItem(ldiCur.downloadUrl);
                PlayListLoader.playLists.remove(PlayListLoader.findHistory(ldiCur.downloadUrl));
                try {
                    PlayListLoader.savePlayListWithXML();
                } catch (Exception ex) {
                    Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                }

                try {
                    JAppToolKit.JRunHelper.runSysCmd("rm -rf " + dl.qvodWorkDir);
                } catch (Exception ex) {
                    Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
                }

                this.dlList.uploadDownloadList();
            }
        }

    }

    private void miClearListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miClearListActionPerformed
        // TODO add your handling code here:
        int result = javax.swing.JOptionPane.showConfirmDialog(null, "真的要清空吗？", "提示", javax.swing.JOptionPane.YES_NO_OPTION);
        if (result == 0) {
            ArrayList data = new ArrayList();
            Set set = this.dlList.downloadItemMap.keySet();
            Iterator its = set.iterator();
            while (its.hasNext()) {
                String s = (String) its.next();
                data.add(this.dlList.downloadItemMap.get(s));
            }
            
            for(Object obj : data)
            {
                delQvodMovieItem((LDownLoadItem)obj);
            }
        }

    }//GEN-LAST:event_miClearListActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(QvodPlayerUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(QvodPlayerUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(QvodPlayerUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(QvodPlayerUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(LvodDownloader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(LvodDownloader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(LvodDownloader.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(LvodDownloader.class.getName()).log(Level.SEVERE, null, ex);
        }

//        if (args != null && args.length > 0) {
//            DisplayManager.videoLibraryClassPath = args[0];
            /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new QvodPlayerUI().setVisible(true);
            }
        });
//        } else {
//            javax.swing.JOptionPane.showMessageDialog(null, "对不起，播放器类库加载失败！");
//        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel btnAbout;
    private LPlayerUILib.JImageButton btnAddMovie;
    private LPlayerUILib.JImageButton btnClose;
    private javax.swing.JLabel btnConfig;
    private LPlayerUILib.JImageButton btnDelMovie;
    private javax.swing.JLabel btnFile;
    private LPlayerUILib.JImageButton btnFullScreen;
    private LPlayerUILib.JImageButton btnGoNext;
    private LPlayerUILib.JImageButton btnLast;
    private LPlayerUILib.JImageButton btnLeftGo;
    private LPlayerUILib.JImageButton btnMin;
    private LPlayerUILib.JImageButton btnPause;
    private LPlayerUILib.JImageButton btnPlay;
    private LPlayerUILib.JImageButton btnRightGo;
    private LPlayerUILib.JImageButton btnStopPlay;
    private LPlayerUILib.JImageButton btnSwitchAddMovie;
    private LPlayerUILib.JImageButton btnSwitchPlaying;
    private LPlayerUILib.JImageButton btnVolumeAdd;
    private LPlayerUILib.JImagePanel contentPanels;
    private lvoddownloader.LDownLoadList dlList;
    private javax.swing.JSlider jslMovieProgress;
    private javax.swing.JSlider jslVolume;
    private javax.swing.JLabel lblMovieInfo;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JMenuItem miAddDVD;
    private javax.swing.JMenuItem miAddDir;
    private javax.swing.JMenuItem miAddFile;
    private javax.swing.JMenuItem miClearList;
    private javax.swing.JMenuItem miLoadList;
    private javax.swing.JMenuItem miSaveList;
    private LPlayerUILib.JImagePanel plListWork;
    private LPlayerUILib.JImagePanel plMenu;
    private LPlayerUILib.JImagePanel plPlayerController;
    private LPlayerUILib.JImagePanel plPlayerToolBar;
    private LPlayerUILib.JImagePanel plProgressBar;
    private LPlayerUILib.JImagePanel plTabButtons;
    private LPlayerUILib.JImagePanel plTask;
    private lvoddownloader.LCurrentPlayList playHistory;
    private VLCPlayerComponent.VLCMediaPlayer player;
    private LPlayerUILib.JImagePanel playerflag;
    private javax.swing.JPopupMenu pmFile;
    private LPlayerUILib.JImagePanel topBar;
    private javax.swing.JTextField txtDownLoadUrl;
    // End of variables declaration//GEN-END:variables

    @Override
    public void processAction(LDownLoadItem sender, String actionName, String args) {
        if (actionName != null && actionName.equals(ActionLists.writeDownloadInfo)) {
            //this.lblTitle.setText(this.defaultSoftName + " - " + args);
        }

        if (actionName != null && actionName.equals(ActionLists.playMovie)) {

            dlList.lastPlayItem = dlList.currentPlay;
            dlList.currentPlay = sender;
            try {
                int percents = (int) ((sender.downloaderObj.getCurrentLength() / sender.downloaderObj.movieFileLength) * 100);
                if (percents >= 98) {
                    if (new File(sender.downloaderObj.qvodWorkDir + "/" + sender.downloaderObj.getMovieFileName()).exists()) {
                        java.awt.EventQueue.invokeLater(new Runnable() {

                            public void run() {
                                dlList.selectedDownLoadItem.setPlayButton(false);
                                dlList.selectedDownLoadItem.setPauseButton(true);
                                lblMovieInfo.setText(dlList.selectedDownLoadItem.movieShowName);
                                jslMovieProgress.setValue(0);
                                playMovie(dlList.selectedDownLoadItem.downloaderObj.qvodWorkDir + "/" + dlList.selectedDownLoadItem.downloaderObj.getMovieFileName());
                            }
                        });
                    }
                } else {
                    String destfile = ConfigLoader.config.downloadDir + "/" + sender.movieShowName;
                    if (new File(destfile).exists()) {
                        java.awt.EventQueue.invokeLater(new Runnable() {

                            public void run() {
                                String destfiless = ConfigLoader.config.downloadDir + "/" + dlList.selectedDownLoadItem.movieShowName;
                                dlList.selectedDownLoadItem.setPlayButton(false);
                                dlList.selectedDownLoadItem.setPauseButton(true);
                                lblMovieInfo.setText(dlList.selectedDownLoadItem.movieShowName);
                                jslMovieProgress.setValue(0);
                                playMovie(destfiless);
                            }
                        });

                    } else {
                        //javax.swing.JOptionPane.showMessageDialog(null, "对不起，影片需要下载到30%才能播放！"); 
                    }
                }
            } catch (Exception ex) {
                Logger.getLogger(QvodPlayerUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (actionName != null && actionName.equals(ActionLists.pauseMovie)) {
            sender.setPlayButton(true);
            sender.setPauseButton(false);
            btnStopPlayMouseClicked(null);
        }
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
                runTimes++;

                long hour = (runTimes / 60) / 60;
                long minute = (runTimes - (hour * 60) * 60) / 60;
                long second = runTimes - ((hour * 60) * 60) - (minute * 60);
//                this.lblProgressInfo.setText("已运行" + hour + "小时" + minute + "分钟" + second + "秒");
            } catch (InterruptedException ex) {
                Logger.getLogger(QvodDownLoad.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    @Override
    public void reportPlayProgress(Object jmp, int percent) {
        this.jslMovieProgress.setValue(percent);
        this.jslMovieProgress.setToolTipText(percent + "%");
        if (percent >= 99) {
            java.awt.EventQueue.invokeLater(new Runnable() {

                public void run() {
                    btnStopPlayMouseClicked(null);
                }
            });
        }
    }

    @Override
    public void reportPlayAction(Object jmp, String string) {
    }

    @Override
    public void runAction(Object sender, String moviePath) {
        this.playMovie(moviePath);
    }
}
